package com.project.forlearningdemo.controller;

import com.project.forlearningdemo.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "CommentController", tags = {"与评论有关的API"})
@RestController
@RequestMapping("comment")
@CrossOrigin
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("搜索评论 这个问我 只可以传三个字段 resourceId 和 commentId, comPageNum")
    @PostMapping("query")
    public String getComment(@RequestBody String idp){
        return commentService.queryComment(idp);
    }

    @ApiOperation("写评论")
    @PostMapping("add")
    public String writeComment(@RequestBody String comment){
        return commentService.addComment(comment);
    }

    @ApiOperation("修改评论，只能修改评论的文字")
    @PostMapping("update")
    public String updateComment(@RequestBody String comment){
        return commentService.updateComment(comment);
    }

    @ApiOperation("删除评论")
    @DeleteMapping("{commentId}")
    public String deleteComment(@PathVariable int commentId){
        return commentService.deleteComment(commentId);
    }
}
